<?php echo $this->load->view('meta'); ?>
<link rel="stylesheet" href="<?=base_url()?>templates/fall2009/css/admin.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?=base_url()?>templates/fall2009/css/datepicker.css" type="text/css" media="screen" />
<script src="<?=base_url();?>js/datepicker.js"></script>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?=$this->load->view('googlemapsapi');?>" type="text/javascript"></script>
<script type="text/javascript">

    function geocode(data){
		var street = data.street.value;
		var city = data.city.value;
		var state = data.state.value;
		if(city!="" && state!=""){
		var address = street + " " + city + " " + state
		var geocoder = new GClientGeocoder();
		geocoder.getLocations(
		    address,
		    function(response) {
		      if (!response || response.Status.code!="200") {
		        data.status.value = null;
		      } else {
				data.status.value = 200;
				place = response.Placemark[0];
		        data.geocode_point.value = place.Point.coordinates[1] + "," + place.Point.coordinates[0];
				if(data.street.value!=""){
					data.street.value = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
					data.city.value = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
					data.state.value = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
				}
				else{
					data.street.value = "";
					data.city.value = place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
					data.state.value = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
				}
				
		      }
		    }
		  );
	}}
	
	function endDate(data){
		
		var end = data.end.value
		if(end==""){
			data.end.value = data.start.value;
		}
		else{
			var start = data.start.value;
			var startYear = start.substring(0,4);
			var startMonth = start.substring(5,7);
			var startDay = start.substring(8,10);
			var endYear = end.substring(0,4);
			var endMonth = end.substring(5,7);
			var endDay = end.substring(8,10);
			if((startYear>endYear) || (startMonth>endMonth) || (startDay>endDay)){
				data.end.value = data.start.value;
			}
		}
	}
    </script>
<title>xa-ncsu | calendar</title>
<?php echo $this->load->view('header'); ?>
<? $hour['all'] = 'all'; $mins['all'] = 'all'?>
<?	for($i=1;$i<=12;$i++){
					$hour[$i] = $i;
				}
				for($i=0;$i<=59;$i++){
					$mins[sprintf("%02d",$i)] = sprintf("%02d",$i);
				}
				$half = array('am'=>'am','pm'=>'pm');
				$homepage = array('0'=>'no','1'=>'yes');
				$repeating = array('no'=>'no','weekly'=>'weekly');
			?>
<?=form_open('calendar/doEditPost');?>
<fieldset>
	<legend><span>edit a calendar entry</span></legend>
	<ol>
		<li><label for="name">subject</label>
			<input type="text" name="name" value="<?=$event->name;?>" size="30" /></li>
		<li><label for="description">description</label>
			<input type="text" name="description" value="<?=$event->description;?>" size="30" /></li>
		<li><label for="repeating">repeat<span style="margin:50px;">stop repeating on</span></label>
			<?= form_dropdown('repeating',$repeating,$event->repeating_type);?>
			<input type="text" name="repeating_end" value="" class="format-y-m-d divider-dash" style="width:100px; margin-left:20px;" maxlength="10"/></li>
		<li><label for="start">start<span style="margin-left:100px;">time<span></label>
			<input type="text" name="start" value="<?=substr($event->start,0,10);?>" class="format-y-m-d divider-dash" style="width:100px; margin=5px;" maxlength="10" onchange="endDate(this.form)"/>
				<?=form_dropdown('start_time_hour', $hour,$startHour,'class="time"');?>:
				<?=form_dropdown('start_time_mins', $mins,$startMin,'class="time""');?>
				<?=form_dropdown('start_time_half', $half,$startHalf,'class="time"');?></li>
		<li><label for="end">end<span style="margin-left:102px;">time</span></label>
			<input type="text" name="end" value="<?=substr($event->end,0,10);?>" class="format-y-m-d divider-dash" style="width:100px; margin=5px;" maxlength="10"/>
			<?=form_dropdown('end_time_hour', $hour,$endHour,'class="time"');?>:
			<?=form_dropdown('end_time_mins', $mins,$endMin,'class="time""');?>
			<?=form_dropdown('end_time_half', $half,$endHalf,'class="time"');?></li>
		<li><label for="street">street</label>
			<input type="text" name="street" id="street" value="<?=$event->street;?>" size="30" class="calendarform" onchange="geocode(this.form);"/></li>
		<li><label for="city">city</label>
			<input type="text" name="city" id="city" value="<?=$event->city;?>" size="30" class="calendarform" onchange="geocode(this.form);"/></li>
		<li><label for="state">state</label>
			<input type="text" name="state" id="state" value="<?=$event->state;?>" size="30" class="calendarform" onchange="geocode(this.form);"/></li>
		<li><label for="category">event category</label>
			<?=form_dropdown('category', $category,'XA');?></li>
		<li><label for="homepage">display on homepage</label>
			<?=form_dropdown('homepage', $homepage,$event->homepage,'class="time"');?></li>
		<li><?=form_submit('','publish')?> <?if($admin) echo anchor('admin/events', 'Cancel'); else echo anchor('calendar/full', 'Cancel');?></li>
			<?=form_hidden('id', $this->uri->segment(3))?>
			<input type="hidden" name="geocode_point" id="geocode_point" value="<?=$event->geocode;?>" />
			<input type="hidden" name="status" id="status" value="$this->validation->status" />
	</ol>
</fieldset>
<?=form_close()?>
<?php echo $this->load->view('footer'); ?>